<script setup>
import {ref} from 'vue'
import axios from 'axios'
import Edit from './components/Edit.vue';
// TODO:列表渲染
const list = ref([])
const getList = async () => {
  const res = await axios.get('/list')
  console.log(res);
  list.value = res.data
}
getList()

// TODO:删除功能
const del = async (id) => {
  await axios.delete(`/del/${id}`)
  getList()
}

// TODO:编辑功能
const editRef = ref(null)
const edit = (row) => {
  editRef.value.open(row)
}
// 更新列表



</script>

<template>
  <div class="app">
    <el-table :data="list" style="width: 100%">
    <el-table-column prop="id" label="ID"  />
    <el-table-column prop="name" label="姓名"  />
    <el-table-column prop="place" label="籍贯"  />
    <el-table-column label="操作">
      <template #default="{row}">
        <el-button link type="primary" size="small" @click="edit(row)"
          >编辑</el-button
        >
        <el-button link type="danger" size="small" @click="del(row.id)">删除</el-button>
      </template>
    </el-table-column>
  </el-table>
  </div>
  <Edit ref="editRef" @update-list="getList" />
</template>

<style scoped>
.app {
  width: 980px;
  margin: 100px auto 0;
}
</style>
